﻿/*
 * 对象解析器
 * 1. 完成从DataTable的DataRow对象到真正对象的解析
 * 2.当前支持 PersonInfo PersonInMySql的解析
 * 
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace HousingDistribution
{
    abstract class ObjectParser
    {
        public abstract PersonInfo ParsePerson(DataRow dr);
        public abstract HousingInfo ParseHousing(DataRow dr);

        
        void DeleteSpecialChr(ref string str)
        {
            if (str == null)
                return;

            foreach (string s in DataDictionary.InvalidChrTable)
            {
                str = str.Replace(s, "");
            }
        }
        //名字中空格的去处
        //特殊字符的过滤
        //日期处理，将未初始化的日期或者解析失败的日期转化为 无效日期（2100）
        protected void DataErrProc(ref PersonInfo info)
        {
            DeleteSpecialChr(ref info.name);
            DeleteSpecialChr(ref info.sex);
            DeleteSpecialChr(ref info.unit);
            DeleteSpecialChr(ref info.adminDuty);
            DeleteSpecialChr(ref info.techRank);
            DeleteSpecialChr(ref info.techTitle);
            DeleteSpecialChr(ref info.curHousingAddr.addr);
            DeleteSpecialChr(ref info.curHousingAddr.roomNum);
            DeleteSpecialChr(ref info.curHousingAddr.area);

            DeleteSpecialChr(ref info.mateInfo.rank);
            DeleteSpecialChr(ref info.mateInfo.unit);

            DeleteSpecialChr(ref info.remarks);

            DateTime erroDate = new DateTime();

            if (info.adminDutyTime.CompareTo(erroDate) == 0)
            {
                info.adminDutyTime = DateProc.InvalidDate();
            }
            if (info.techRankTime.CompareTo(erroDate) == 0)
            {
                info.techRankTime = DateProc.InvalidDate();
            }
            if (info.techTitleTime.CompareTo(erroDate) == 0)
            {
                info.techTitleTime = DateProc.InvalidDate();
            }
            if (info.curRankBeforeTime.CompareTo(erroDate) == 0)
            {
                info.curRankBeforeTime = DateProc.InvalidDate();
            }
            if (info.workTime.CompareTo(erroDate) == 0)
            {
                info.workTime = DateProc.InvalidDate();
            }
            if (info.schoolTime.CompareTo(erroDate) == 0)
            {
                info.schoolTime = DateProc.InvalidDate();
            }
            if (info.signupTime.CompareTo(erroDate) == 0)
            {
                info.signupTime = DateProc.InvalidDate();
            }
            if (info.retirementTime.CompareTo(erroDate) == 0)
            {
                info.retirementTime = DateProc.InvalidDate();
            }
        }

        protected PersonMaritalEnum GetMarital(string mateName, string remarks)
        {
            if (mateName.Length == 0 && remarks.Length == 0)
                return PersonMaritalEnum.Unmarried;
            else if (mateName.Length != 0 && remarks.Length == 0)
                return PersonMaritalEnum.Married;
            else
            {
                string[] maritalStatus = DataDictionary.Instance().PersonMaritalStatus();

                foreach (string marital in maritalStatus)
                {
                    if (remarks.Contains(marital))
                    {
                        return DataDictionary.Instance().GetMorital(marital);
                    }
                }

                if (mateName.Length > 0)
                    return PersonMaritalEnum.Married;
                else
                    return PersonMaritalEnum.Unmarried;
            }
        }

        protected PersonMaritalEnum GetMarital(int n)
        {
            if (Enum.IsDefined(typeof(PersonMaritalEnum), n))
                return (PersonMaritalEnum)n;
            else
               // return PersonMaritalEnum.Unknown;
                return PersonMaritalEnum.Married;
        }

        protected WithArmyStatusEnum GetWitharmy(int n)
        {
            if (Enum.IsDefined(typeof(WithArmyStatusEnum), n))
                return (WithArmyStatusEnum)n;
            else
                return WithArmyStatusEnum.Unkown;
        }

        //如果没退休，默认在职
        protected WorkStatusEnum GetWorkStatus(DateTime retirementTime)
        {
            if (retirementTime.CompareTo(DateProc.InvalidDate()) != 0)
            {
                return WorkStatusEnum.Retiree;
            }
            return WorkStatusEnum.Onduty;
        }

        protected DateProc dateProc = new DateProc("YY.MM.DD");
    }

    class PersonParserFromMySql : ObjectParser
    {
        public override PersonInfo ParsePerson(DataRow dr)
        {
            try
            {
                PersonInfo personInfo = new PersonInfo();

                int id = (int)dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.ID)];

                string name = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.NAME)].ToString();
                int type = (int)dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.TYPE)];
                string sex = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.SEX)].ToString();
                string unit = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.UNIT)].ToString();
                string adminDuty = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.ADMIN_DUTY)].ToString();

                DateTime adminDutyTime;
                object o = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.ADMIN_DUTY_TIME)];
                if (o is DateTime)
                    adminDutyTime = (DateTime)o;
                else
                    adminDutyTime = DateProc.InvalidDate();

                string techRank = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.TECH_RANK)].ToString();

                DateTime techRankTime;
                o = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.TECH_RANK_TIME)];
                if (o is DateTime)
                    techRankTime = (DateTime)o;
                else
                    techRankTime = DateProc.InvalidDate();

                string techTitle = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.TECH_TITLE)].ToString();

                DateTime techTitleTime;
                o = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.TECH_TITLE_TIME)];
                if (o is DateTime)
                    techTitleTime = (DateTime)o;
                else
                    techTitleTime = DateProc.InvalidDate();

                DateTime curRankBeforTime;
                o = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.CUR_RANK_BEFORE_TIME)];
                if (o is DateTime)
                    curRankBeforTime = (DateTime)o;
                else
                    curRankBeforTime = DateProc.InvalidDate();

                DateTime workTime;
                o = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.WORK_TIME)];
                if (o is DateTime)
                    workTime = (DateTime)o;
                else
                    workTime = DateProc.InvalidDate();

                DateTime schoolTime;
                o = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.SCHOOL_TIME)];
                if (o is DateTime)
                    schoolTime = (DateTime)o;
                else
                    schoolTime = DateProc.InvalidDate();

                DateTime signupTime;
                o = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.SIGNUP_TIME)];
                if (o is DateTime)
                    signupTime = (DateTime)o;
                else
                    signupTime = DateProc.InvalidDate();

                int serviceLength = 0;
                //if (workTime!=DateProc.InvalidDate()&&work)
                o = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.SERVICE_LENGTH)];
                if (o is int)
                    serviceLength = (int)o;
                //int serviceLength = (int)dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.SERVICE_LENGTH)];

                DateTime retirementTime;
                o = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.RETIREMENT_TIME)];
                if (o is DateTime)
                    retirementTime = (DateTime)o;
                else
                    retirementTime = DateProc.InvalidDate();

                string mateName = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.MATE_NAME)].ToString();
                string mateRank = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.MATE_RANK)].ToString();
                string mateUnit = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.MATE_UNIT)].ToString();
                MateInfo mateInfo = new MateInfo();
                mateInfo.name = mateName;
                mateInfo.unit = mateUnit;
                mateInfo.rank = mateRank;

                string remarks = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.REMARKS)].ToString();
                string nameInitial = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.NAME_INITIAL)].ToString();
                int housingEligible = (int)dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.HOUSING_ELIGIBLE)];
                int bothEmployee = (int)dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.BOTH_EMPLOYEE)];
                string evaluation = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.EVALUATION)].ToString();

                string curHousingAddr = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.HOUSE_ADDR)].ToString();
                string curHousingArea = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.HOUSE_AREA)].ToString();
                HousingInfo houseinfo = new HousingInfo();
                houseinfo.addr = curHousingAddr;
                houseinfo.area = curHousingArea;

                string housingInfoStr = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.HOUSING_INFO)].ToString();
                string formerHousingId = dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.FORMER_HOUSING_ID)].ToString();
                int marital = (int) dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.MARITAL)];

                int workStatus = (int)dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.WORK_STATUS)];

                int withArmy = (int)dr[DataDictionary.Instance().PersonTableFieldName(PersonColConsts.WITHARMY)];

                personInfo.idperson = id;
                personInfo.name = name;
                personInfo.type = (PersonTypeEnum)type;
                personInfo.sex = sex;
                personInfo.unit = unit;
                personInfo.adminDuty = adminDuty;
                personInfo.adminDutyTime = adminDutyTime;
                personInfo.techRank = techRank;
                personInfo.techRankTime = techRankTime;
                personInfo.techTitle = techTitle;
                personInfo.techTitleTime = techTitleTime;
                personInfo.curRankBeforeTime = curRankBeforTime;
                personInfo.workTime = workTime;
                personInfo.schoolTime = schoolTime;
                personInfo.signupTime = signupTime;
                personInfo.retirementTime = retirementTime;
                personInfo.curHousingAddr = houseinfo;
                personInfo.mateInfo = mateInfo;

                personInfo.workStatus = (WorkStatusEnum)workStatus;

                personInfo.remarks = remarks;
                personInfo.housingEligible = housingEligible;
                personInfo.bothEmployee = bothEmployee;
                personInfo.evaluation = evaluation;
                personInfo.marital = GetMarital(marital);
                personInfo.withArmy = GetWitharmy(withArmy);

                personInfo.housingInfo = new List<HousingOccupancyInfo>();
                housingInfoProc.ParseFromMySql(ref personInfo.housingInfo, housingInfoStr);
                personInfo.formerHousingId = new List<int>();
                housingInfoProc.ParseFromMySql(ref personInfo.formerHousingId, formerHousingId);

                DataErrProc(ref personInfo);

                return personInfo;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                PersonInfo personInfo = new PersonInfo();
                return personInfo;
            }
        }

        public override HousingInfo ParseHousing(DataRow dr)
        {
            HousingInfo info = new HousingInfo();
            return info;
        }

        HousingInfoProc housingInfoProc = new HousingInfoProc();
    }

    class ArmyManParserFromExcel : ObjectParser
    {
        public override PersonInfo ParsePerson(DataRow dr)
        {
            try
            {
                object[] elements = dr.ItemArray;

                PersonInfo personInfo = new PersonInfo();
                string name = elements[0].ToString().Trim();

                if (name.Length == 0)
                    return personInfo;

                string sex = elements[1].ToString().Trim();
                string unit = elements[2].ToString().Trim();
                string adminDuty = elements[3].ToString().Trim();

                string adminDutyTimeStr = elements[4].ToString().Trim();
                DateTime adminDutyTime = this.dateProc.Parse(adminDutyTimeStr);

                string techRank = elements[5].ToString().Trim();

                string rankTimeStr = elements[6].ToString().Trim();
                DateTime techRankTime = this.dateProc.Parse(rankTimeStr);

                string techTitle = elements[7].ToString().Trim();

                string techTitleStr = elements[8].ToString().Trim();
                DateTime techTitleTime = this.dateProc.Parse(techTitleStr);

                //副职时间
                string curRankBeforTimeStr = elements[9].ToString().Trim();
                DateTime curRankBeforTime = this.dateProc.Parse(curRankBeforTimeStr);
  
                string workTimeStr = elements[10].ToString().Trim();
                DateTime workTime = this.dateProc.Parse(workTimeStr);

                string schoolTimeStr = elements[11].ToString().Trim();
                DateTime schoolTime = this.dateProc.Parse(schoolTimeStr);

                string signupTimeStr = elements[12].ToString().Trim();
                DateTime signupTime = this.dateProc.Parse(signupTimeStr);

                string mateName = elements[13].ToString().Trim();
                string mateUnit = elements[14].ToString().Trim();
                string mateRank = elements[15].ToString().Trim();

                MateInfo mateInfo = new MateInfo();
                mateInfo.name = mateName;
                mateInfo.unit = mateUnit;
                mateInfo.rank = mateRank;

                string curHousingAddr = elements[16].ToString().Trim();
                string curHousingRoomNum = elements[17].ToString().Trim();
                string curHousingArea = elements[18].ToString().Trim();

                HousingInfo curHousing = new HousingInfo();
                curHousing.addr = curHousingAddr;
                curHousing.roomNum = curHousingRoomNum;
                curHousing.area = curHousingArea;

                string remarks = null;
                string evaluation = null;

                //excel文件不确定一定有remarks字段，因此通过elements的长度来判断
                if (elements.Length >= 20)
                {
                    remarks = elements[19].ToString().Trim();
                    //从remarks获取evaluation信息
                    string[] evaluationEnum = DataDictionary.Instance().PersonEvaluation();

                    foreach (string str in evaluationEnum)
                    {
                        //evaluation必需从高到底排序,因此先匹配者为最佳值
                        if (remarks.Contains(str))
                        {
                            evaluation = str;
                            break;
                        }
                    }
                }

                personInfo.name = name;
                personInfo.sex = sex;
                personInfo.unit = unit;
                personInfo.adminDuty = adminDuty;
                personInfo.adminDutyTime = adminDutyTime;
                personInfo.techRank = techRank;
                personInfo.techRankTime = techRankTime;
                personInfo.techTitle = techTitle;
                personInfo.techTitleTime = techTitleTime;

                personInfo.curRankBeforeTime = curRankBeforTime;
                
                personInfo.workTime = workTime;
                personInfo.schoolTime = schoolTime;
                personInfo.signupTime = signupTime;

                personInfo.mateInfo = mateInfo;
                personInfo.curHousingAddr = curHousing;

                personInfo.remarks = remarks;

                //默认具备分房资格
                personInfo.housingEligible = 1;

                personInfo.evaluation = evaluation;

                personInfo.marital = GetMarital(mateName, remarks);

                DateTime retirementTime = DateProc.InvalidDate();
                personInfo.workStatus = GetWorkStatus(retirementTime);

                DataErrProc(ref personInfo);

                return personInfo;
            }
            catch (Exception)
            {
                PersonInfo personInfo = new PersonInfo();
                return personInfo;
            }
        }

        public override HousingInfo ParseHousing(DataRow dr)
        {
            object[] elements = dr.ItemArray;

            HousingInfo houseInfo = new HousingInfo();
            houseInfo.addr = elements[16].ToString().Trim();
            houseInfo.roomNum = elements[17].ToString().Trim();
            houseInfo.area = elements[18].ToString().Trim();

            return houseInfo;
        }
    }

    class StaffParserFromExcel : ObjectParser
    {
        public override PersonInfo ParsePerson(DataRow dr)
        {
            try
            {
                object[] elements = dr.ItemArray;
                PersonInfo personInfo = new PersonInfo();
                string name = elements[0].ToString().Trim();

                if (name.Length == 0)
                    return personInfo;

                string sex = elements[1].ToString().Trim();
                string unit = elements[2].ToString().Trim();
                string adminDuty = elements[3].ToString().Trim();

                string adminDutyTimeStr = elements[4].ToString().Trim();
                DateTime adminDutyTime = this.dateProc.Parse(adminDutyTimeStr);

                string techTitle = elements[5].ToString().Trim();

                string titleTimeStr = elements[6].ToString().Trim();
                DateTime techTitleTime = this.dateProc.Parse(titleTimeStr);

                string curRankBeforTimeStr = elements[7].ToString().Trim();
                DateTime curRankBeforTime = this.dateProc.Parse(curRankBeforTimeStr);

                string workTimeStr = elements[8].ToString().Trim();
                DateTime workTime = this.dateProc.Parse(workTimeStr);

                string schoolTimeStr = elements[9].ToString().Trim();
                DateTime schoolTime = this.dateProc.Parse(schoolTimeStr);

                string signupTimeStr = elements[10].ToString().Trim();
                DateTime signupTime = this.dateProc.Parse(signupTimeStr);

                string mateName = elements[11].ToString().Trim();
                string mateUnit = elements[12].ToString().Trim();
                string mateRank = elements[13].ToString().Trim();

                MateInfo mateInfo = new MateInfo();
                mateInfo.name = mateName;
                mateInfo.unit = mateUnit;
                mateInfo.rank = mateRank;

                string curHousingAddr = elements[14].ToString().Trim();
                string curHousingRoomNum = elements[15].ToString().Trim();
                string curHousingArea = elements[16].ToString().Trim();
                HousingInfo curHousing = new HousingInfo();
                curHousing.addr = curHousingAddr;
                curHousing.roomNum = curHousingRoomNum;
                curHousing.area = curHousingArea;

                string remarks = elements[17].ToString().Trim();

                personInfo.name = name;
                personInfo.sex = sex;
                personInfo.unit = unit;
                personInfo.adminDuty = adminDuty;
                personInfo.adminDutyTime = adminDutyTime;
                personInfo.techTitle = techTitle;
                personInfo.techTitleTime = techTitleTime;
                personInfo.curRankBeforeTime = curRankBeforTime;
                personInfo.workTime = workTime;
                personInfo.schoolTime = schoolTime;
                personInfo.signupTime = signupTime;

                personInfo.mateInfo = mateInfo;
                personInfo.curHousingAddr = curHousing;
                personInfo.remarks = remarks;

                personInfo.marital = GetMarital(mateName, remarks);

                DateTime retirementTime = DateProc.InvalidDate();
                personInfo.workStatus = GetWorkStatus(retirementTime);

                //默认具备分房资格
                personInfo.housingEligible = 1;

                DataErrProc(ref personInfo);

                return personInfo;
            }
            catch (Exception)
            {
                PersonInfo personInfo = new PersonInfo();
                return personInfo;
            }
        }

        public override HousingInfo ParseHousing(DataRow dr)
        {
            object[] elements = dr.ItemArray;
            HousingInfo houseInfo = new HousingInfo();
            houseInfo.addr = elements[14].ToString().Trim();
            houseInfo.roomNum = elements[15].ToString().Trim();
            houseInfo.area = elements[16].ToString().Trim();

            return houseInfo;
        }
    }

    //退休工人不参加分房，但是数据要入库。
    class WorkerParserFromExcel : ObjectParser
    {
        public override PersonInfo ParsePerson(DataRow dr)
        {
            try
            {
                object[] elements = dr.ItemArray;
                PersonInfo personInfo = new PersonInfo();
                string name = elements[0].ToString().Trim();

                if (name.Length == 0)
                    return personInfo;

                string sex = elements[1].ToString().Trim();
                string unit = elements[2].ToString().Trim();

                string techTitle = elements[3].ToString().Trim();

                string workTimeStr = elements[4].ToString().Trim();
                DateTime workTime = this.dateProc.Parse(workTimeStr);

                string schoolTimeStr = elements[5].ToString().Trim();
                DateTime schoolTime = this.dateProc.Parse(schoolTimeStr);

                string signupTimeStr = elements[6].ToString().Trim();
                DateTime signupTime = this.dateProc.Parse(signupTimeStr);

                string retirementTimeStr = elements[7].ToString().Trim();
                DateTime retirementTime = this.dateProc.Parse(retirementTimeStr);

                personInfo.workStatus = GetWorkStatus(retirementTime);

                string mateName = elements[9].ToString().Trim();
                string mateUnit = elements[10].ToString().Trim();
                string mateRank = elements[11].ToString().Trim();

                MateInfo mateInfo = new MateInfo();
                mateInfo.name = mateName;
                mateInfo.unit = mateUnit;
                mateInfo.rank = mateRank;

                string curHousingAddr = elements[12].ToString().Trim();
                string curHousingRoomNum = elements[13].ToString().Trim();
                string curHousingArea = elements[14].ToString().Trim();
                HousingInfo curHousing = new HousingInfo();
                curHousing.addr = curHousingAddr;
                curHousing.roomNum = curHousingRoomNum;
                curHousing.area = curHousingArea;

                string remarks = elements[15].ToString().Trim();

                personInfo.name = name;
                personInfo.sex = sex;
                personInfo.unit = unit;
                personInfo.techTitle = techTitle;
                personInfo.workTime = workTime;
                personInfo.schoolTime = schoolTime;
                personInfo.signupTime = signupTime;
                personInfo.retirementTime = retirementTime;

                personInfo.mateInfo = mateInfo;
                personInfo.curHousingAddr = curHousing;

                personInfo.remarks = remarks;

                //退休无分房资格。
                if (retirementTimeStr != "")
                    personInfo.housingEligible = 0;
                else
                    personInfo.housingEligible = 1;

                personInfo.marital = GetMarital(mateName, remarks);
                
                DataErrProc(ref personInfo);

                return personInfo;
            }
            catch (Exception)
            {
                PersonInfo personInfo = new PersonInfo();
                return personInfo;
            }
        }

        public override HousingInfo ParseHousing(DataRow dr)
        {
            object[] elements = dr.ItemArray;
            HousingInfo houseInfo = new HousingInfo();
            houseInfo.addr = elements[12].ToString().Trim();
            houseInfo.roomNum = elements[13].ToString().Trim();
            houseInfo.area = elements[14].ToString().Trim();

            return houseInfo;
        }
    }

    class NCOParserFromExcel : ObjectParser
    {
        public override PersonInfo ParsePerson(DataRow dr)
        {
            try
            {
                object[] elements = dr.ItemArray;

                PersonInfo personInfo = new PersonInfo();
                string name = elements[0].ToString().Trim();

                if (name.Length == 0)
                    return personInfo;

                string sex = elements[1].ToString().Trim();
                string unit = elements[2].ToString().Trim();

                string techTitle = elements[3].ToString().Trim();

                string titleTimeStr = elements[4].ToString().Trim();
                DateTime techTitleTime = this.dateProc.Parse(titleTimeStr);

                string workTimeStr = elements[5].ToString().Trim();
                DateTime workTime = this.dateProc.Parse(workTimeStr);

                string signupTimeStr = elements[6].ToString().Trim();
                DateTime signupTime = this.dateProc.Parse(signupTimeStr);

                string mateName = elements[7].ToString().Trim();
                string mateUnit = elements[8].ToString().Trim();
                string mateRank = elements[9].ToString().Trim();

                MateInfo mateInfo = new MateInfo();
                mateInfo.name = mateName;
                mateInfo.unit = mateUnit;
                mateInfo.rank = mateRank;

                string curHousingAddr = elements[10].ToString().Trim();
                string curHousingRoomNum = elements[11].ToString().Trim();
                string curHousingArea = elements[12].ToString().Trim();
                HousingInfo curHousing = new HousingInfo();
                curHousing.addr = curHousingAddr;
                curHousing.roomNum = curHousingRoomNum;
                curHousing.area = curHousingArea;

                string remarks = elements[13].ToString().Trim();

                personInfo.name = name;
                personInfo.sex = sex;
                personInfo.unit = unit;
                personInfo.techTitle = techTitle;
                personInfo.techTitleTime = techTitleTime;
                personInfo.workTime = workTime;
                personInfo.signupTime = signupTime;

                personInfo.mateInfo = mateInfo;
                personInfo.curHousingAddr = curHousing;

                personInfo.remarks = remarks;

                personInfo.marital = GetMarital(mateName, remarks);

                DateTime retirementTime = DateProc.InvalidDate();
                personInfo.workStatus = GetWorkStatus(retirementTime);

                //默认具备分房资格
                personInfo.housingEligible = 1;

                DataErrProc(ref personInfo);

                return personInfo;
            }
            catch (Exception)
            {
                PersonInfo personInfo = new PersonInfo();
                return personInfo;
            }
        }

        public override HousingInfo ParseHousing(DataRow dr)
        {
            object[] elements = dr.ItemArray;
            HousingInfo houseInfo = new HousingInfo();
            houseInfo.addr = elements[10].ToString().Trim();
            houseInfo.roomNum = elements[11].ToString().Trim();
            houseInfo.area = elements[12].ToString().Trim();

            return houseInfo;
        }
    }

    class HousingOriginalInfoFromMySql
    {
        public HousingOriginalInfoFromMySql()
        {
        }

        public HousingOriginalInfo Parse(DataRow dr)
        {
            try
            {
                HousingOriginalInfo info = new HousingOriginalInfo();

                info.idhousing = Convert.ToInt32(dr[DataDictionary.Instance().HousingTableFieldName(HousingColConsts.ID)]);
                info.housingType = dr[DataDictionary.Instance().HousingTableFieldName(HousingColConsts.TYPE)].ToString();
                info.housingFullAddr = dr[DataDictionary.Instance().HousingTableFieldName(HousingColConsts.FULL_ADDR)].ToString();
                info.streetNo = dr[DataDictionary.Instance().HousingTableFieldName(HousingColConsts.STREET_NO)].ToString();
                info.buildingNo = dr[DataDictionary.Instance().HousingTableFieldName(HousingColConsts.BUILDING_NO)].ToString();
                info.doorWay = dr[DataDictionary.Instance().HousingTableFieldName(HousingColConsts.DOORWAY)].ToString();
                info.floor = dr[DataDictionary.Instance().HousingTableFieldName(HousingColConsts.FLOOR)].ToString();
                info.roomNo = dr[DataDictionary.Instance().HousingTableFieldName(HousingColConsts.ROOM_NO)].ToString();
                info.housingArea = Convert.ToInt32(dr[DataDictionary.Instance().HousingTableFieldName(HousingColConsts.AREA)]);
                info.housingUse = dr[DataDictionary.Instance().HousingTableFieldName(HousingColConsts.HOUSING_USE)].ToString();
                info.housingProperty = dr[DataDictionary.Instance().HousingTableFieldName(HousingColConsts.HOUSING_PROPERTY)].ToString();
                info.remarks = dr[DataDictionary.Instance().HousingTableFieldName(HousingColConsts.REMARKS)].ToString();

                return info;
            }
            catch (Exception)
            {
                HousingOriginalInfo info = new HousingOriginalInfo();
                return info;
            }
        }

        private DateProc dateProc = new DateProc("YY-MM-DD");
    }
}
